(function () {
	"use strict";
	app.controller('networkCtrl', ['$scope', 'httpLoad', '$rootScope', '$modal', '$state', '$timeout',
		function ($scope, httpLoad, $rootScope, $modal, $state, $timeout) {
			$rootScope.moduleTitle = '软件管理 > 软件管理';//定义当前页
	$rootScope.link = '/statics/css/graph.css';
			$scope.isListView = true;
			$scope.param = {
				page:1,
				rows: 8,
				params: JSON.stringify([{"param": {"type": "VMWARE"}, "sign": "EQ"}])
			};
			//获取云主机列表
			$scope.getData = function (page) {
				$scope.param.page = page || $scope.param.page;
				httpLoad.loadData({
					url: '/cloudVendor/list',
					method: 'POST',
					data: $scope.param,
					noParam: true,
					success: function (data) {
						if (data.success) {
							$scope.countData = data.data.rows;
							$scope.totalCount = data.data.total;
						}
					}
				});
			};
			$scope.getData(1);
			//搜索
			$scope.search = function () {
				//对参数进行处理，去除空参数
				var toObjFormat = function (obj) {
					for (var a in obj) {
						if (obj[a] == "") delete obj[a];
					}
					return obj;
				}
				var params = [];
				var param1 = toObjFormat({
					name: $scope.name
				});
				var param2 = toObjFormat({
					type: 'VMWARE'
				});
				if (angular.toJson(param1).length > 2) params.push({param: param1, sign: 'LK'});
				params.push({param: param2, sign: 'EQ'});
				$scope.param = {
					page: 1,
					rows: 10,
					params: angular.toJson(params)
				}
				$scope.getData();
			}
			//重置搜索条件
			$scope.reset = function () {
				var obj = ['name'];
				angular.forEach(obj, function (data) {
					$scope[data] = '';
				})
			}
			//返回
			$scope.goAction = function (flag, id, $event) {
				switch (flag / 1) {
					case 1:
						$state.go('app.config.cloudVendorVm');
						break;
					case 2:
						$event.stopPropagation();
						$state.go('app.config.cloudVendorVm', {id: id});
						break;
					case 3:
						$event.stopPropagation();
						$state.go('app.config.vmwareTab', {id: id});
						sessionStorage.setItem('vmTabvendor', JSON.stringify({id: id}));
						sessionStorage.setItem('vmwaretabLocation', 'vmDatacenter');
						break;
					case 4:
						$state.go('app.config.cloudVendorVmDetail', {id: id});
						break;
				}
			};
			$scope.remove = function ($event, id) {
				$event.stopPropagation();
				var modalInstance = $modal.open({
					templateUrl: '/statics/tpl/config/supplier/remove.html',
					controller: 'removeSupplierModalCtrl',
					resolve: {
						removeData: function () {
							return {id: id};
						}
					}
				});
				modalInstance.result.then(function () {
					$scope.getData();
				}, function () {
				});
			};
		}
	]);
	//删除ctrl
	app.controller('removeSupplierModalCtrl', ['$scope', '$modalInstance', 'httpLoad', 'removeData',
		function ($scope, $modalInstance, httpLoad, removeData) {
			$scope.ok = function () {
				httpLoad.loadData({
					url: '/cloudVendor/remove',
					method: 'POST',
					data: removeData,
					success: function (data) {
						if (data.success) {
							//console.log(removeData);
							$scope.pop('平台删除成功');
							$modalInstance.close();
						}
					}
				});
			};
			$scope.cancel = function () {
				$modalInstance.dismiss('cancel'); // 退出
			};
		}]);
})();
